{if isset($products)}
<script src="/js/fastEdit.js?{echo time()}" type="text/javascript"></script>
<div class="form-group">
    <label class="col-lg-4" for="sort">Sortuj Produkty według</label>
    <select id="order">
        <option value="1" {if $order==1} selected {/if}>Daty dodania rosnąco</option>
        <option value="2" {if $order==2} selected {/if}>Daty dodania malejąco</option>
        <option value="3" {if $order==3} selected {/if}>Ceny rosnąco</option>
        <option value="4" {if $order==4} selected {/if}>Ceny malejąco</option>
        <option value="5" {if $order==5} selected {/if}>Oceny rosnąco</option>
        <option value="6" {if $order==6} selected {/if}>Oceny malejąco</option>
        <option value="7" {if $order==7} selected {/if}>Dostępności rosnąco</option>
        <option value="8" {if $order==8} selected {/if}>Dostępności malejąco</option>
        <option value="9" {if $order==9} selected {/if}>Nazwy rosnąco</option>
        <option value="10" {if $order==10} selected {/if}>Nazwy malejąco</option>
    </select>   
</div> 
<table class="table table-hover table-bordered table-striped table-responsive">
    <thead>
        <tr>
            <th>Nazwa</th>
            <th>Cena Brutto</th>
            <th>Vat</th>
            <th>Ilość</th>
            <th>Producent</th>
            <th>Kategoria</th>
            <th>Widoczny</th>
            <th>Zapisz</th>
        </tr>
    </thead>

    {foreach $product in $products}
    <form>       
        <input type="hidden" name="shopname" value="$shop->URL" id="shopname">
        <tr>
             <input type="hidden" name="ProductID" value="{echo $product['ProductID']['ProductID']}">
            <td><input type="text" value="{echo $product['ProductID']['Name']}" name="ProductName"></td>
            <td>
                <input class="input-sm" style="width: 120px" type="number" min="0" step="0.01" value="{echo $product['ProductID']['GrossPrice']}" name="GrossPrice"> zł
            </td>
            <td>
                <div class="form-group" id="vatSelect">
                    <div id="editProduct" class="col-lg-7"> 
                        <div class="btn-group" role="group">
                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                {echo $product['ProductID']["VAT"]} %<span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu " role="menu" >
                                <li {if $product['ProductID']["VAT"]==0} class="active" {/if}><input type="hidden" value="0" name="vat" ><a>0%</a></li>
                                <li {if $product['ProductID']["VAT"]==5} class="active" {/if}><input type="hidden" value="5" name="vat"><a>5%</a></li>
                                <li {if $product['ProductID']["VAT"]==8} class="active" {/if}><input type="hidden" value="8" name="vat"><a>8%</a></li>
                                <li {if $product['ProductID']["VAT"]==22} class="active" {/if}><input type="hidden" value="22" name="vat"><a>22%</a></li>
                                <li {if $product['ProductID']["VAT"]==23} class="active" {/if}><input type="hidden" value="23" name="vat"><a>23%</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </td>
            <td>
                <input class="input-sm" style="width: 60px" type="number" min="0"  value="{echo $product['ProductID']['Amount']}" name="Amount">
           </td>
            <td>
                <div class="form-group" id="manufacturers">
                    <div id="editProducer" class="col-lg-7"> 
                        <div class="btn-group" role="group">
                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="true">
                                {echo $product['ProductID']["ManufacturerID"]["Name"] }<span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu " role="menu">
                                {foreach $manufacturer in  $manufacturers}
                                {if $product['ProductID']["ManufacturerID"]["ManufacturerID"]==$manufacturer->ManufacturerID}
                                <li class="active">
                                    {/if}
                                    {else} <li> {/else}
                                    <input type="hidden" name="manufacturer" value="$manufacturer->ManufacturerID"><a>$manufacturer->Name</a></li>
                                {/foreach}
                            </ul>
                        </div>
                        <p class="alert-danger" style="padding-left: 10px">
                            {if isset($errors)}
                            {echo \view\View::showErrors($errors, "ManufacturerID")}  
                            {/if}
                        </p>
                    </div>
                </div>
            </td>
            <td>
                <div class="form-group" id="categories">
                    <div id="editCategory" class="col-lg-7"> 
                        <div class="btn-group" role="group">
                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false" title="zmiana kategorii spowoduje wymazanie wartości cech produktu powiązanych z daną kategorią dla danego produktu">
                                {echo  $product['ProductID']["CategoryID"]["Name"]}<span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu " role="menu" id="categoriesList">
                                {foreach $category in  $categories}

                                {if $product['ProductID']["CategoryID"]["CategoryID"]==$category->CategoryID}
                                <li style="margin-left: {echo $category->Depth*10 }px" class="active">
                                    {/if}
                                    {else} <li style="margin-left: {echo $category->Depth*10 }px"> {/else}
                                    <input type="hidden" name="category" value="$category->CategoryID" disabled>
                                    <a>$category->Name</a>
                                </li>
                                {/foreach}
                            </ul>
                        </div>
                    </div>
                </div>
            </td>
            <td>
                <div class="form-group" id="Active">
                    <div id="editProduct" class="col-lg-7"> 
                        <div class="btn-group" role="group">
                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                {if $product['ProductID']["Active"]==0} Nie {/if}
                                {if $product['ProductID']["Active"]==1} Tak {/if}<span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu " role="menu" >
                                <li {if $product['ProductID']["Active"]==0} class="active" {/if}><input type="hidden" value="0" name="vat" ><a>Nie</a></li>
                                <li {if $product['ProductID']["Active"]==1} class="active" {/if}><input type="hidden" value="5" name="vat"><a>Tak</a></li>
                            </ul>
                        </div>
                    </div>
                </div>               
            </td>
            <td><input type="button" value="zapisz" class="submitPayment alert alert-info"></td>
        </tr>
    </form>
    {/foreach}

</table>
{/if}
{else}
<h2>Nie dodałeś jeszcze żadnego produktu</h2>
{/else}
<a href="/$shop->URL/ShopAdmin_Products/add/"><button class="btn btn-toolbar btn-info">Dodaj Produkt</button></a>